require('es6-promise').polyfill();
export const getListData=(data)=>{
    return {
        type:'GETNEWS',
        data
    }
}
export const getCommenData=(data)=>{
    return {
        type:'GETCOMMEN',
        data
    }
}
export const putCommen=(data)=>{
    return {
        type:'PUTCOMMEN',
        data
    }
}
export function fetchList(params){
    return dispatch=>{
        var url="http://localhost:3000/news/data/"+params;
        return fetch(url,{method:'GET'})
        .then(res=>{
            return res.json()
        })
        .then(data=>{
            dispatch(getListData(data))
        })
    }
}
export function fetchCommenList(id){
    return dispatch=>{
        var url="http://localhost:3000/comment/list";
        return fetch(url,{
            method:'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body:id
        })
        .then(res=>{
            return res.json()
        })
        .then(data=>{
            dispatch(getCommenData(data))
        })
    }
}
export function SubmitCommens(params){
    return dispatch=>{
        var url="http://localhost:3000/comment/data";
        return fetch(url,{
            method:'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body:params
        })
        .then(res=>{
            return res.json()
        })
        .then(data=>{
            dispatch(putCommen(data))
        })
    }
}